package com.hm.system.web.su;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.bind.annotation.ModelAttribute;

import com.hm.common.model.LoginUserInfo;
import com.hm.common.util.CommonDef;

/**
 * @author shishun.wang
 * @date 下午8:48:21 2016年8月22日
 * @version 1.0
 * @describe 
 */
public abstract class BaseController {

	protected HttpServletRequest request;

	protected HttpServletResponse response;

	@ModelAttribute
	public void setReqAndRes(HttpServletRequest request, HttpServletResponse response) {
		this.request = request;
		this.response = response;
	}

	protected String currentUserId() throws Exception {
		LoginUserInfo userInfo = (LoginUserInfo) request.getSession()
				.getAttribute(CommonDef.BaseInit.SessionOrCookieToken.SESSION_LOGIN_USER_INFO);
		if (null == userInfo) {
			throw new Exception("会话超时");
		}
		return userInfo.getId();
	}

}
